package com.itheima.mapper;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClazzMapper {


    //    @Results({
//            @Result(column = "begin_date" , property = "beginDate"),
//            @Result(column = "end_date" , property = "endDate"),
//            @Result(column = "master_id" , property = "masterId")
//    })
    /*List<Clazz> queryClazzs(Clazz clazz,
                            @Param("page") int page,
                            @Param("pageSize") int pageSize);*/

    /**
     * 添加部门数据 - 传递多个参数时,可以把多个参数封装到一个对象中 , 然后通过 #{属性名} 来获取对象属性
     */

    @Insert("insert into clazz(name, room, begin_date, end_date, master_id, subject) " +
            "values(#{name}, #{room}, #{beginDate},#{endDate},#{masterId},#{subject})")
    void add(Clazz clazz);

    /**
     * 根据ID删除班级信息
     */
    @Delete("delete from clazz where id = #{id}")
    void deleteById(Integer id);

    /**
     * 根据id查询班级信息
     * @param id
     */
    @Select("select c.*, e.name masterName from clazz c left join emp e on c.master_id = e.id where c.id = #{id}")
    Clazz getById(Integer id);
//select id, name, room, begin_date, end_date, master_id, subject, create_time, update_time from clazz where id = #{id}
    /**
     * 修改信息
     */
    @Update("update clazz set name = #{name},room = #{room}, begin_date = #{beginDate},end_date = #{endDate},master_id=#{masterId},subject=#{subject},create_time=#{createTime},update_time=#{updateTime} where id=#{id} ")
    void update(Clazz clazz);

/*("update clazz set " +"name = #{name},"
        +
        "room = #{room}," +
        "begin_date = #{beginDate}," +
        "end_date = #{endDate}," +
        "master_id = #{masterId}," +
        "subject = #{subject} " +
        "update_time = #{updateTime}" +
        " where id=#{id}" )*/

    List<Clazz> list(ClazzQueryParam clazzQueryParam);
    @Select("select * from clazz")
    List<Clazz> findAll();
}
